def wo(word):
    words = {
        "zero": "0",
        "one": "1",
        "two": "2",
        "three": "3",
        "four": "4",
        "five": "5",
        "six": "6",
        "seven": "7",
        "eight": "8",
        "nine": "9"
    }
    return words.get(word)

def s(n):
    if n <= 1:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True

put = input().split()
if len(put) != 3:
    print("Wrong input")
else:
    n = "".join([wo(word) for word in put])
    if not n.isdigit() or len(n) != 3:
        print("Wrong input")
    else:
        number = int(n)
        lp = None
        up = None
        i = 1
        while True:
            if number - i >= 0 and s(number - i):
                lp = number - i
                break
            if s(number + i):
                up = number + i
                break
            i += 1
        
        if lp is not None:
            print(lp)
        elif up is not None:
            print(up)


